<?php

namespace App\Model;


use Illuminate\Http\Request;
use mysql_xdevapi\Exception;

class RoomOpLog extends BaseModel
{
    protected $connection = 'mysql';
    protected $table = 'room_op_log';
    protected $fillable = [ 'user_id', 'op', 'room_id','desc'];

    public function getOpAttribute($value){
        return ['取消认证', '认证', '整顿中'][$value];
    }

    public function createData($data = []){
        if(empty($data)) throw new Exception('参数错误');
        return self::create($data);
    }

    public function getList($room_id){
        return self::where('room_id',$room_id)->with(['users:id,name'])->orderBy('id','desc')->get();
    }

    public function users(){
        return $this->belongsTo(Users::class,'user_id','id')
            ->withDefault();
    }
}
